import sys
sys.path.append('.')
from manimlib import *
from upload_videos._2023.GMS2BeginnerTutorial.header import *
from utils.codeview import CodePlane, CodeView
from utils.string import StrSearcher

class Intro(IntroTemplate):
    str2 = '第5节 代码基本语法 前半'

class SubTitle1(SubTitleTemplate):
    text = '基本思维'

class SubTitle2(SubTitleTemplate):
    text = '注释'

class SubTitle3(SubTitleTemplate):
    text = '赋值与运算语句'

class SubTitle4(SubTitleTemplate):
    text = '基本数据类型'

class SubTitle5(SubTitleTemplate):
    text = '函数调用'

class _1(Scene):
    def construct(self) -> None:
        code = '''var inst = instance_create_layer(...);
inst.direction = point_direction(...);
inst.speed = 5;
'''
        c = CodePlane(code)
        se = StrSearcher(code).s('var', C_KEYWORD).s('inst', C_TMPVAR).s('instance_create_layer', C_FUNC)\
            .s('inst', C_TMPVAR).s('direction', C_BUILTIN_VAR).s('point_direction', C_FUNC)\
            .s('inst', C_TMPVAR).s('speed', C_BUILTIN_VAR).s('5', C_DIGIT)
        for rg, col in se.results:
            c.lines.set_code_color(*rg, col)

        arrow = Arrow(ORIGIN, RIGHT * 0.5, buff=0).set_color(BLUE_D).next_to(c.lines[0], LEFT, SMALL_BUFF)
        self.add(c)
        self.wait()

        # self.wait()
        # self.play(FadeIn(c, UP))
        # self.wait(0.1)
        # self.play(GrowArrow(arrow))
        # self.wait(0.5)
        # self.play(arrow.animate.next_to(c.lines[1], LEFT, SMALL_BUFF), run_time=0.5)
        # self.wait(0.5)
        # self.play(arrow.animate.next_to(c.lines[2], LEFT, SMALL_BUFF), run_time=0.5)
        # self.wait()
        # self.play(*map(FadeOut, (c, arrow)))
        # self.wait()


